﻿package util;

public class Filter {
	
	String str="";
	
	//使用现有的字符串构造一个过滤器,
	public Filter(String source)
	{
		if(source!=null)
			this.str=source;
	}
	
	//返回过滤后的字符串;
	public static String filtrate(String str)
	{
		if(str.equals(""))
			return str;
		
		//str=str.replaceAll("<", "&lt;");
		//str=str.replaceAll(">", "&gt;");
		//str=str.replaceAll("\"", "&quot;");
		//str=str.replaceAll("\n", "<br>");
		//str=str.replaceAll("\r", "");
		//str=str.replaceAll("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
		//str=str.replaceAll(" ", "&nbsp;");
		str=str.replaceAll("'", "-danyinhao-");
		//str=str.replaceAll("(", "-zuokuohao-");	//不知道为啥会出错???
		//str=str.replaceAll(")", "-youkuohao-");
		//str=str.replaceAll("script", "ssccrriipptt");
		//str=str.replaceAll("frame", "ffrraammee");
		
		return str;
		
	}	
	
	//返回过滤后的字符串;
	public static String filtrateFQuestion(String str)
	{
		if(str.equals(""))
			return str;
		
		str=str.replaceAll("<", "&lt;");
		str=str.replaceAll(">", "&gt;");
		str=str.replaceAll("\"", "&quot;");
		str=str.replaceAll("\n", "<br>");
		str=str.replaceAll("\r", "");
		str=str.replaceAll("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
		str=str.replaceAll(" ", "&nbsp;");
		str=str.replaceAll("'", "-danyinhao-");
		//str=str.replaceAll("(", "-zuokuohao-");	//不知道为啥会出错???
		//str=str.replaceAll(")", "-youkuohao-");
		//str=str.replaceAll("script", "ssccrriipptt");
		//str=str.replaceAll("frame", "ffrraammee");
		
		return str;
		
	}	
	
	//返回过滤后的字符串;
	public static String unfiltrateFQuestion(String str)
	{
		if(str.equals(""))
			return str;
		
		str=str.replaceAll("&lt;", "<");
		str=str.replaceAll("&gt;",">" );
		str=str.replaceAll("&quot;","\"");
		str=str.replaceAll("<br>","\n" );
		str=str.replaceAll( "","\r");
		str=str.replaceAll("&nbsp;&nbsp;&nbsp;&nbsp;","\t" );
		str=str.replaceAll( "&nbsp;"," ");
		str=str.replaceAll( "-danyinhao-","'");
		//str=str.replaceAll("(", "-zuokuohao-");	//不知道为啥会出错???
		//str=str.replaceAll(")", "-youkuohao-");
		//str=str.replaceAll("script", "ssccrriipptt");
		//str=str.replaceAll("frame", "ffrraammee");
		
		return str;
		
	}	
	//返回过滤后的字符串,仅对显示新闻列表的时候,过滤新闻内容中的特殊字符有用;
	public static String filtrateNewsContent(String str)
	{
		if(str.equals(""))
			return str;
		
		str=str.replaceAll("<", "&lt;");
		str=str.replaceAll(">", "&gt;");
		str=str.replaceAll("\"", "&quot;");
		//str=str.replaceAll("\n", "<br>");
		//str=str.replaceAll("\r", "");
		str=str.replaceAll("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
		str=str.replaceAll(" ", "&nbsp;");
		//str=str.replaceAll("'", "-danyinhao-");
		//str=str.replaceAll("(", "-zuokuohao-");	//不知道为啥会出错???
		//str=str.replaceAll(")", "-youkuohao-");
		//str=str.replaceAll("script", "ssccrriipptt");
		//str=str.replaceAll("frame", "ffrraammee");
		
		return str;
		
	}
	
	//仅仅过滤单引号
	public static String  filtrateDanyinhao(String str)
	{
		if(null==str)
			return "";
		return str.replaceAll("'", "-danyinhao-");
	}
	//反过滤单引号
	public static String unFiltrateDanyinhao(String str)
	{
		if(null==str)
			return "";
		return str.replaceAll("-danyinhao-", "'");

	}
	//反过滤单引号
	public static String unFiltrateQuestionContent(String str)
	{
		if(null==str)
			return "";

		 str.replaceAll("-danyinhao-", "'");
		 str.replaceAll("\n", "<br>");
		 return str;
	}
	
	//过滤单引号和回车
	public static String FiltrateQuestionContent(String str)
	{
		if(null==str)
			return "";
		 str.replaceAll("'", "-danyinhao-");
		 //str.replaceAll("<br>","\n");
		 return str;

	}
	//去掉字符串中的所有"
	public static String removeAllQuot(String str)
	{
		if(null==str)
			return "";
		return str.replaceAll("\"", "");
	}
	
	//返回过滤前的字符串;
	public String unFiltrate()
	{
		if(null==str)
			return "";
		if(str.equals(""))
			return str;
		
		//str=str.replaceAll("&lt;","<" );
		//str=str.replaceAll("&gt;",">");
		//str=str.replaceAll("&quot;","\"");
		//str=str.replaceAll("<br>","\n" );
		//str=str.replaceAll("","\r");
		//str=str.replaceAll("&nbsp;&nbsp;&nbsp;&nbsp;","\t");
		//str=str.replaceAll("&nbsp;"," ");
		str=str.replaceAll("-danyinhao-","'");
		str=str.replaceAll("-zuokuohao-","(");
		str=str.replaceAll("-youkuohao-",")");
		return str;
	}
	
	//过滤新闻中的下载信息,转到下载页面
	//
	public static String filtrateDownload(String str)
	{
		if(str==null)
			return "";
		//str = str.replaceAll("/zizhuwebsit/UploadFile//", "/zizhuwebsit/news_download.jsp?file=");
		str = str.replaceAll("/zizhuwebsit/UploadFile//", "../news_download.jsp?file=");
		return str;
	}
	
	
	//仅过滤\,在文件路径中使用
	public static String filtrateFanxiegang(String str)
	{
		return str.replaceAll("\\", "-fanxiegang-");
	}
	//解码过滤\
	public static String unfiltrateFanxiegang(String str){
		if(null == str){
			return "";
		}
		else{
			return str.replaceAll("-fanxiegang-", "\\");
		}
	}

	
	//过滤工作人员信息中的特殊字符
	public static String filtrateWorker(String str)
	{
		if(str.equals(""))
		return str;
	
	str=str.replaceAll("<", "&lt;");
	str=str.replaceAll(">", "&gt;");
	str=str.replaceAll("\"", "&quot;");
	str=str.replaceAll("\n", "<br>");
	//str=str.replaceAll("\r", "-hui-");
	str=str.replaceAll("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
	str=str.replaceAll(" ", "&nbsp;");
	str=str.replaceAll("'", "-danyinhao-");
	
	return str;
	}
	//解码过滤工作人员信息中的特殊字符
	//public static String unfiltrateWorker(String str){
	public static String unfiltrateWorker(String str)
	{
		if(null==str)
			return "";
		str=str.replaceAll("&lt;", "<");
		str=str.replaceAll("&gt;",">" );
		str=str.replaceAll("&quot;","\"");
		str=str.replaceAll("<br>","\n" );
		//str=str.replaceAll( "-hui-","\r");
		str=str.replaceAll("&nbsp;&nbsp;&nbsp;&nbsp;","\t" );
		str = str.replaceAll("-danyinhao-", "'");
		str = str.replaceAll( "&nbsp;"," ");
		return str;

	}
	
	public static String quchuhtml(String str)
	{
		if(null==str)
			return "";
		str=str.replaceAll("&lt;", "");
		str=str.replaceAll("&gt;","" );
		str=str.replaceAll("&quot;","");
		str=str.replaceAll("<br>","" );
		//str=str.replaceAll( "-hui-","\r");
		str=str.replaceAll("&nbsp;&nbsp;&nbsp;&nbsp;","" );
		str = str.replaceAll("-danyinhao-", "");
		str = str.replaceAll( "&nbsp;","");
		return str;

	}
	
	//去除空格
	public static String konggegun(String str)
	{
		if(null==str)
			return "";
		str = str.replaceAll( "&nbsp;","");
		return str;

	}
	
}
